package de.sabram.upb.specs.serializer;

import com.google.inject.Inject;
import de.sabram.upb.specs.services.MapGrammarAccess;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.IGrammarAccess;
import org.eclipse.xtext.RuleCall;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.AbstractElementAlias;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.GroupAlias;
import org.eclipse.xtext.serializer.analysis.GrammarAlias.TokenAlias;
import org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynNavigable;
import org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynTransition;
import org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer;

@SuppressWarnings("all")
public class MapSyntacticSequencer extends AbstractSyntacticSequencer {

	protected MapGrammarAccess grammarAccess;
	protected AbstractElementAlias match_TypeMapFile_MAPCHAINSKeyword_2_a;
	protected AbstractElementAlias match_TypeMapFile_MAPCHAINSKeyword_2_p;
	protected AbstractElementAlias match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPRULEKeyword_1_0__q;
	protected AbstractElementAlias match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPSYMKeyword_0_0__q;
	
	@Inject
	protected void init(IGrammarAccess access) {
		grammarAccess = (MapGrammarAccess) access;
		match_TypeMapFile_MAPCHAINSKeyword_2_a = new TokenAlias(true, true, grammarAccess.getTypeMapFileAccess().getMAPCHAINSKeyword_2());
		match_TypeMapFile_MAPCHAINSKeyword_2_p = new TokenAlias(true, false, grammarAccess.getTypeMapFileAccess().getMAPCHAINSKeyword_2());
		match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPRULEKeyword_1_0__q = new GroupAlias(false, true, new TokenAlias(true, true, grammarAccess.getTypeMapFileAccess().getMAPCHAINSKeyword_2()), new TokenAlias(false, false, grammarAccess.getTypeMapFileAccess().getMAPRULEKeyword_1_0()));
		match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPSYMKeyword_0_0__q = new GroupAlias(false, true, new TokenAlias(true, true, grammarAccess.getTypeMapFileAccess().getMAPCHAINSKeyword_2()), new TokenAlias(false, false, grammarAccess.getTypeMapFileAccess().getMAPSYMKeyword_0_0()));
	}
	
	@Override
	protected String getUnassignedRuleCallToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if(ruleCall.getRule() == grammarAccess.getDelimiterRule())
			return getDelimiterToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getRewriteRule())
			return getRewriteToken(semanticObject, ruleCall, node);
		else if(ruleCall.getRule() == grammarAccess.getSTRINGRule())
			return getSTRINGToken(semanticObject, ruleCall, node);
		return "";
	}
	
	/**
	 * Delimiter: ':' | '::=';
	 */
	protected String getDelimiterToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return ":";
	}
	
	/**
	 * Rewrite: '<' RewriteRHS '>';
	 */
	protected String getRewriteToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "<$>";
	}
	
	/**
	 * terminal STRING	: 
	 * 			'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
	 * 			"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
	 * 		;
	 */
	protected String getSTRINGToken(EObject semanticObject, RuleCall ruleCall, INode node) {
		if (node != null)
			return getTokenText(node);
		return "\"\"";
	}
	
	@Override
	protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) {
		if (transition.getAmbiguousSyntaxes().isEmpty()) return;
		List<INode> transitionNodes = collectNodes(fromNode, toNode);
		for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) {
			List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax);
			if(match_TypeMapFile_MAPCHAINSKeyword_2_a.equals(syntax))
				emit_TypeMapFile_MAPCHAINSKeyword_2_a(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_TypeMapFile_MAPCHAINSKeyword_2_p.equals(syntax))
				emit_TypeMapFile_MAPCHAINSKeyword_2_p(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPRULEKeyword_1_0__q.equals(syntax))
				emit_TypeMapFile___MAPCHAINSKeyword_2_a_MAPRULEKeyword_1_0__q(semanticObject, getLastNavigableState(), syntaxNodes);
			else if(match_TypeMapFile___MAPCHAINSKeyword_2_a_MAPSYMKeyword_0_0__q.equals(syntax))
				emit_TypeMapFile___MAPCHAINSKeyword_2_a_MAPSYMKeyword_0_0__q(semanticObject, getLastNavigableState(), syntaxNodes);
			else acceptNodes(getLastNavigableState(), syntaxNodes);
		}
	}

	/**
	 * Syntax:
	 *     'MAPCHAINS'*
	 */
	protected void emit_TypeMapFile_MAPCHAINSKeyword_2_a(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     'MAPCHAINS'+
	 */
	protected void emit_TypeMapFile_MAPCHAINSKeyword_2_p(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     ('MAPCHAINS'* 'MAPRULE')?
	 */
	protected void emit_TypeMapFile___MAPCHAINSKeyword_2_a_MAPRULEKeyword_1_0__q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
	/**
	 * Syntax:
	 *     ('MAPCHAINS'* 'MAPSYM')?
	 */
	protected void emit_TypeMapFile___MAPCHAINSKeyword_2_a_MAPSYMKeyword_0_0__q(EObject semanticObject, ISynNavigable transition, List<INode> nodes) {
		acceptNodes(transition, nodes);
	}
	
}
